﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SurehealthForms.CashierLogin
{
    public partial class CashTransaction : Form
    {
        double Total;
        private double m_tempChange;

        public double TempChange
        {
            get { return m_tempChange; }
            set { m_tempChange = value; }
        }
        public CashTransaction(string TotalToCharge)
        {
            InitializeComponent();
            Total = convertString(TotalToCharge);
            totalText.Text = "£" + Total;
        }

        private void totalGivenText_TextChanged(object sender, EventArgs e)
        {
            //Setting Change
            string changeGiven;
            changeGiven = "£0.00";

            
            TempChange = Total - convertString(totalGivenText.Text) ;

            changeGiven = TempChange.ToString("F");
            changeGiven = "£" + changeGiven.ToString();
            changeText.Text = changeGiven;
        }

        //Converting Textbox string to Double
        private double convertString(string box)
        {
            double value;
            if (box == String.Empty) //Check if textbox is empty and set at 0 if true
            {
                value = 0;
            }
            else //Else convert to double
            {
                value = double.Parse(box);
            }
            return value;
        }

        private void DoneButton_Click(object sender, EventArgs e)
        {
            if (TempChange <= 0)
            {
                this.Hide();
            }
            else
            {
            }
        }

        
    }
}
